import tkinter as tk
import time

class FloatingClock:
    def __init__(self, master):
        self.master = master
        master.overrideredirect(True)
        master.attributes('-topmost', True)
        master.geometry("+850+0")

        self.label = tk.Label(master, font=('Helvetica', 48, 'bold'), bg='black', fg='white')
        self.label.pack(fill='both', expand=True)
        
        self.update_clock()

        # 绑定鼠标事件
        self.label.bind("<ButtonPress-1>", self.start_move)
        self.label.bind("<ButtonRelease-1>", self.stop_move)
        self.label.bind("<B1-Motion>", self.on_motion)

        self.x = 0
        self.y = 0

    def update_clock(self):
        current_time = time.strftime('%H:%M:%S')
        self.label.config(text=current_time)
        self.master.after(1000, self.update_clock)

    def start_move(self, event):
        self.x = event.x
        self.y = event.y

    def stop_move(self, event):
        self.x = None
        self.y = None

    def on_motion(self, event):
        deltax = event.x - self.x
        deltay = event.y - self.y
        x = self.master.winfo_x() + deltax
        y = self.master.winfo_y() + deltay
        self.master.geometry("+{}+{}".format(x, y))

if __name__ == "__main__":
    root = tk.Tk()
    clock = FloatingClock(root)
    root.mainloop()
